home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d20 / msgq160s.arc / SHELL.C < prev    next >
Text File  |  1991-10-26  |  2KB  |  84 lines

  1. /*
  2.  * Shell to a program, swapping to EMS or Disk
  3.  * Written by P.J. Muller
  4.  */
  5.  
  6. #include <dos.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <process.h>
  10. #include "execswap.h"        /* link with EXECSWAP.OBJ */
  11. #include "shell.h"
  12.  
  13. unsigned char swapping_enabled = 1;
  14. void (far *shell_message)(char swapmode, long amount) = NULL;
  15.  
  16. extern void far *_brklvl;
  17.  
  18. /*
  19.  * Execute a Dos command
  20.  * If path==NULL, execute COMSPEC
  21.  * command may be NULL
  22.  * Return TRUE iff ok
  23.  */
  24.  
  25. unsigned char shell(char *path, char *command)
  26. {
  27.   void far *top;
  28.   unsigned int status = 1;
  29.   char temp[100];
  30.   char ctemp[140];
  31.  
  32. /* Default parameters */
  33.  
  34.   if (path == NULL)
  35.     if ((path = getenv("COMSPEC")) == NULL)
  36.       return 0;
  37.  
  38. /* Check for non-swapping mode */
  39.  
  40.   if (!swapping_enabled) {
  41.     if (shell_message != NULL)
  42.       shell_message(SWAP_NONE, 0);
  43.  
  44.     if (spawnlp(P_WAIT, path, path, command, NULL) == -1)
  45.       return 0;
  46.     else
  47.       return 1;
  48.   } /* if */
  49.  
  50. /* Swapping mode: Convert to Pascal strings */
  51.  
  52.   if (command == NULL)
  53.     command = "";
  54.  
  55.   strcpy(temp+1, path);
  56.   temp[0] = strlen(temp+1);        /* Pascal string */
  57.  
  58.   strcpy(ctemp+1, command);
  59.   ctemp[0] = strlen(ctemp+1);        /* Pascal string */
  60.  
  61. /* Get size to swap, could probably do better here */
  62.  
  63.   /* top = MK_FP(*(int *)MK_FP(_psp, 2), 0); */
  64.   top = _brklvl;
  65. #ifndef __LARGE__
  66. #error Dunno if the line above will work
  67. #endif
  68.  
  69.   if (!InitExecSwap(top, "")) {
  70.     return 0;
  71.   } else {
  72.     if (shell_message != NULL)
  73.       shell_message(EmsAllocated() ? SWAP_EMS : SWAP_DISK, BytesSwapped());
  74.  
  75.     /* SwapVectors */
  76.     status = ExecWithSwap(temp, ctemp);
  77.     /* SwapVectors */
  78.   } /* else */
  79.  
  80.   ShutdownExecSwap();        /* Must be called */
  81.  
  82.   return (status == 0);
  83. } /* shell */
  84.